<template>
  <div style="text-align: left">退号窗口</div>
  <hr/>
  <div style="text-align: left">
    <el-form :inline="true" :model="formRecord">
      <el-form-item label="病历号">
        <el-input  placeholder="请输入患者病历号" clearable  v-model="formRecord.caseNumber"/>
      </el-form-item>
      <el-form-item label="患者姓名">
        <el-input  placeholder="请输入患者姓名" clearable v-model="formRecord.realName"/>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="loadRegList">查询</el-button>
      </el-form-item>

    </el-form>
  </div>
  <hr/>
  <el-table :data="backRegList" style="width: 100%">
    <el-table-column type="index" :index="indexMethod" />
    <el-table-column prop="caseNumber" label="病历号" />
    <el-table-column prop="realName" label="患者姓名" />
    <el-table-column prop="gender" label="性别" />
    <el-table-column prop="cardNumber" label="身份证" width="230px"/>
    <el-table-column prop="registMethod" label="付款方式"/>

    <!--    <el-table-column prop="visitState" label="看诊状态">
          <template #default="{row}">
            {{getState(row)}}
          </template>
        </el-table-column>-->

    <el-table-column label="操作" >
      <template #default="{ row }">
        <el-button type="primary" round @click="backRecord(row)">退号</el-button>
      </template>
    </el-table-column>
  </el-table>
  <hr/>
</template>

<script setup>
//定义输出患者查询列表的表单
import {onMounted, reactive, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";

const formRecord=reactive({
  caseNumber:'',
  realName:''
});
//定义退号患者列表
const backRegList=ref([]);
//定义分页总数
const total=ref();
onMounted(()=>{
  loadRegList();
});

//发送请求加载已经挂号患者列表
function loadRegList(){
  axios.get("http://localhost/his/backRegisterList?caseNumber="
      +formRecord.caseNumber+"&realName="+formRecord.realName)
      .then((response)=>{
        //console.log(response);
        backRegList.value=response.data.backRegList;
        total.value=response.data.total;
      })
      .catch((error)=>{
        console.log(error);
      });
}
//计算行编号
function indexMethod(index){
  index++;
  return index;
}

//定义函数发送退号ajax请求
function backRecord(row){
  axios.get("http://localhost/his/backRegister?id="+
      row.id+"&state=4")
      .then((response)=>{
        //console.log(response);
        ElMessage(response.data.msg);
        loadRegList();
      })
      .catch((error)=>{
        console.log(error);
      });
}
</script>

<style scoped>

</style>